package com.ai.module.mj.domain.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;

/**
 */
@Data
@ApiModel("提交结果")
public class SubmitResultVO {

	private String uuid = UUID.randomUUID().toString().toLowerCase(Locale.ROOT);

	@ApiModelProperty(value = "状态码: 1(提交成功), " +
			"21(已存在), 22(排队中)," +
			" other(错误)",
			required = true,
			example = "1")
	private int code;

	@ApiModelProperty(value = "描述",
			required = true,
			example = "提交成功")
	private String message;

	@ApiModelProperty(value = "任务ID",
			example = "1320098173412546")
	private String taskId;

	@ApiModelProperty("任务进度")
	private String progress ="0";
	@ApiModelProperty("图片路径")
	private String imageUrl;

	@ApiModelProperty("缩略图路径")
	private String scaleUrl;


	@ApiModelProperty(value = "扩展字段")
	private Map<String, Object> properties = new HashMap<>();

	public SubmitResultVO setProperty(String name, Object value) {
		this.properties.put(name, value);
		return this;
	}

	public SubmitResultVO removeProperty(String name) {
		this.properties.remove(name);
		return this;
	}

	public Object getProperty(String name) {
		return this.properties.get(name);
	}

	@SuppressWarnings("unchecked")
	public <T> T getPropertyGeneric(String name) {
		return (T) getProperty(name);
	}

	public <T> T getProperty(String name, Class<T> clz) {
		return clz.cast(getProperty(name));
	}

	public static SubmitResultVO of(int code, String description, String result) {
		return new SubmitResultVO(code, description, result);
	}



	public static SubmitResultVO fail(int code, String description) {
		return new SubmitResultVO(code, description, null);
	}

	private SubmitResultVO(int code, String message, String result) {
		this.code = code;
		this.message = message;
		this.taskId = result;
	}

	public static SubmitResultVO of() {
		return new SubmitResultVO(200, "success", "success");
	}

	public SubmitResultVO(String imageUrl, String scalePath) {
		this.imageUrl = imageUrl;
		this.scaleUrl = scalePath;
	}
}
